package com.cn.sl.server.api.system.log.aspect.service.impl

import com.cn.sl.server.api.system.log.aspect.annotation.WriteLog
import com.cn.sl.server.api.system.log.aspect.service.ProcessLogService
import com.cn.sl.server.api.system.user.dao.rdb.AdminUserDao
import jakarta.servlet.http.HttpServletRequest
import org.aspectj.lang.JoinPoint
import org.springframework.stereotype.Service
import java.lang.reflect.Method

/**
 * 默认处理日志实现
 *
 * @author 阮雪峰
 */
@Service
class DefaultProcessLogServiceImpl(
    val adminUserDao: AdminUserDao,
//    val logService: LogService,
    val request: HttpServletRequest,
) : ProcessLogService {

    override fun process(
        targetClass: Class<*>,
        targetClassWriteLog: WriteLog?,
        targetMethod: Method,
        targetMethodWriteLog: WriteLog,
        joinPoint: JoinPoint,
    ) {
        /*val name: String = adminUserDao.findById(StpUtil.getLoginIdAsLong()).username
        val parameterJsonContent = getParameterJsonContent(joinPoint)
        val log = SaveLogDto(
            menu = targetClassWriteLog?.value ?: "",
            operate = targetMethodWriteLog.value,
            name = name,
            ip = ServletUtil.getClientIP(request),
            extend = DefaultLogExtendEntity(parameterJsonContent)
        )
        logService.save(log)*/
    }

    /* private fun getParameterJsonContent(joinPoint: JoinPoint): String {
         val signature = joinPoint.signature as MethodSignature
         val parameterNames = signature.parameterNames
         val map = hashMapOf<String, Any>()
         for ((index, arg) in joinPoint.args.withIndex()) {
             if (arg is HttpServletRequest || arg is HttpServletResponse || arg is MultipartFile) {
                 continue
             }
             map[parameterNames[index]] = arg
         }
         return JsonUtils.toJsonStr(map)
     }*/
}
